package com.xbongbong.pro.statistic.help.strategy.field;

import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.statistic.help.strategy.field.method.CategoryIdFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.ComboFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.ComboListFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.DateTimeFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.DefaultFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.DepartmentFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.LabelFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.LinkBusinessFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.NumFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.PublicGroupFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.SaleStageFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.StarFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.SwitchFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.TeamFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.UserFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.WorkOrderNodeStatusFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.WorkOrderStageFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.WorkOrderStatusFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.field.method.WorkOrderV2ProcessNodeFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.method.PurchaseableGoodsFieldAnalysis;
import com.xbongbong.pro.statistic.help.strategy.method.ReceivablePeriodFieldAnalysis;
import com.xbongbong.pro.statistic.pojo.FieldAnalysisPojo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 字段解析
 * @author zhouwq
 * @date 2020/9/8 10:16
 */

@Component
public class FieldAnalysisContext {

    private FieldAnalysisStrategy fieldAnalysisStrategy;

    @Resource
    private NumFieldAnalysis numFieldAnalysis;
    @Resource
    private UserFieldAnalysis userFieldAnalysis;
    @Resource
    private TeamFieldAnalysis teamFieldAnalysis;
    @Resource
    private CategoryIdFieldAnalysis categoryIdFieldAnalysis;
    @Resource
    private DateTimeFieldAnalysis dateTimeFieldAnalysis;
    @Resource
    private ComboFieldAnalysis comboFieldAnalysis;
    @Resource
    private SwitchFieldAnalysis switchFieldAnalysis;
    @Resource
    private WorkOrderStageFieldAnalysis workOrderStageFieldAnalysis;
    @Resource
    private DepartmentFieldAnalysis departmentFieldAnalysis;
    @Resource
    private ComboListFieldAnalysis comboListFieldAnalysis;
    @Resource
    private LinkBusinessFieldAnalysis linkBusinessFieldAnalysis;
    @Resource
    private LabelFieldAnalysis labelFieldAnalysis;
    @Resource
    private ReceivablePeriodFieldAnalysis receivablePeriodFieldAnalysis;
    @Resource
    private PurchaseableGoodsFieldAnalysis purchaseableGoodsFieldAnalysis;
    @Resource
    private SaleStageFieldAnalysis saleStageFieldAnalysis;
    @Resource
    private WorkOrderV2ProcessNodeFieldAnalysis workOrderV2ProcessNodeFieldAnalysis;
    @Resource
    private PublicGroupFieldAnalysis publicGroupFieldAnalysis;

    public void initStrategy(FieldTypeEnum fieldTypeEnum) {
        FieldAnalysisStrategy strategy;
        switch (fieldTypeEnum) {
            case NUM:
            case STAGE_RATIO:
            case COMPUTED_FIELD:
                strategy = numFieldAnalysis;
                break;
            case COUSERID:
            case OWNERID:
                strategy = teamFieldAnalysis;
                break;
            case CREATORID:
            case USER:
            case USER_GROUP:
                strategy = userFieldAnalysis;
                break;
            case CATEGORY_ID:
                strategy = categoryIdFieldAnalysis;
                break;
            case ADDTIME:
            case UPDATETIME:
            case DATETIME:
            case CLOSETIME:
            case ENDTIME:
                strategy = dateTimeFieldAnalysis;
                break;
            case COMBO:
            case COMBO_NUM:
            case RADIO_GROUP:
                strategy = comboFieldAnalysis;
                break;
            case SWITCH:
                strategy = switchFieldAnalysis;
                break;
            case WORK_ORDER_STATUS:
                strategy = new WorkOrderStatusFieldAnalysis();
                break;
            case WORK_ORDER_NODE_STATUS:
                strategy = new WorkOrderNodeStatusFieldAnalysis();
                break;
            case WORK_ORDER_STAGE:
                strategy = workOrderStageFieldAnalysis;
                break;
            case DEPT_GROUP:
            case DEPT:
            case DEPARTMENTID:
                strategy = departmentFieldAnalysis;
                break;
            case CHECKBOX_GROUP:
            case COMBO_CHECK:
                strategy = comboListFieldAnalysis;
                break;
            case STAR:
                strategy = new StarFieldAnalysis();
                break;
            case LINK_BUSINESS_SINGLE:
            case LINK_BUSINESS_MULTI:
                strategy = linkBusinessFieldAnalysis;
                break;
            case LABEL:
                strategy = labelFieldAnalysis;
                break;
            case ACCOUNT_PERIOD:
                strategy = receivablePeriodFieldAnalysis;
                break;
            case PURCHASEABLE_GOODS:
                strategy = purchaseableGoodsFieldAnalysis;
                break;
            case STAGE_THRUSTER:
                strategy = saleStageFieldAnalysis;
                break;
            case NODE_ID:
                strategy = workOrderV2ProcessNodeFieldAnalysis;
                break;
            case PUBLIC_GROUP:
                strategy = publicGroupFieldAnalysis;
            default:
                strategy = new DefaultFieldAnalysis();
                break;
        }
        this.fieldAnalysisStrategy = strategy;
    }

    public Map<String, String> strategyMethod(FieldAnalysisPojo fieldAnalysisPojo) throws XbbException {
        return fieldAnalysisStrategy.doAnalysisField(fieldAnalysisPojo);
    }

}
